package cn.com.freelibra.forum.web.method;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import cn.com.freelibra.forum.web.view.NewsMessageObject;

public class NewsMessage {
	
	private static final String url = "http://news.baidu.com/";

	/*
	 * 获取新闻资讯
	 */
	public static List<NewsMessageObject> getNewMessages(){
		List<NewsMessageObject> newsMessageList = new ArrayList<>();
		try {
			Document doc = Jsoup.connect(url).get();
			Elements hot = doc.getElementsByClass("bold-item").select("a");
			for(int i=0;i<hot.size();i++){
				NewsMessageObject news=new NewsMessageObject();
				news.setMessage(hot.get(i).text().toString());
				news.setUrl(hot.get(i).attr("href").toString());
				newsMessageList.add(news);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return newsMessageList;
		
	}
}
